package br.com.sgi.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateUtil {
	private static SessionFactory sessionFactory = buildSessionFactory();
	private static ServiceRegistry serviceRegistry;

	private static SessionFactory buildSessionFactory() {

	    Configuration configuration = new Configuration();
	    configuration.configure();

	    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();        
	    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

	    return sessionFactory;
	}
	
	public static Session getSession() {
		return sessionFactory.getCurrentSession();
	}
}
